package com.game.classes
{
	public class MathHelper
	{
		public function MathHelper()
		{
		}
	
		// X Value for fixed position controller (Maps each degree with a certain pixel) 
		// Not in for accelerated mode
		public static function XCoordWithAngleAndWidth(_angle : Number, _gameWidth: Number, _avatarWidth:Number):Number{
	 			var number : Number;
	 			
				if ( _angle <= 360.0 && _angle>= 270.0){
					number = (1-(_angle - 270)/90.0);
					return (_gameWidth/2 + (_gameWidth/2) * number)	- _avatarWidth/2;
				} else if ( _angle>=0.0 && _angle <= 90.0){
					number = _angle / 90.0;
					return ((_gameWidth/2 - (_gameWidth/2)*number)) -_avatarWidth/2 ;
	 			} else if (_angle >= 90.0 && _angle <= 180.0)
	 				return 0 - _avatarWidth/2; 
	 			else
	 				return _gameWidth - _avatarWidth/2;
	 			
	 		}
			// Y Value for fixed position controller (Maps each degree with a certain pixel) 
			// Not in for accelerated mode	
	 		public static function YCoordWithAngleAndWidth(_angle : Number, _gamHeight: Number, _avatarHeight:Number):Number{
	 			var number : Number;
	 			
				if ( _angle <= 360.0 && _angle>= 270.0){
					number = (1-(_angle - 270)/90.0);
					return (_gamHeight/2 + (_gamHeight/2) * number)	- _avatarHeight/2;
				} else if ( _angle>=0.0 && _angle <= 90.0){
					number = _angle / 90.0;
					return ((_gamHeight/2 - (_gamHeight/2)*number)) -_avatarHeight/2 ;
	 			} else if (_angle >= 90.0 && _angle <= 180.0)
	 				return 0 - _avatarHeight/2; 
	 			else
	 				return _gamHeight - _avatarHeight/2;
	 			
	 		}
	 	
		
		public static function XZAngle(xAccel : Number, zAccel : Number):Number{
				trace(xAccel.toString() + " " + zAccel.toString());
				zAccel = -zAccel;
				var angleRad : Number;
				angleRad = Math.atan(zAccel/xAccel) * (180.0/Math.PI);
				if (xAccel >= 0.0 && zAccel <= 0.0)
					angleRad = 360.0 + angleRad;
				else if (xAccel <=0.0 && zAccel <=0.0)
					angleRad = 180.0 + angleRad;
				else if (xAccel<= 0.0 && zAccel>=0.0)
					angleRad = 180.0 + angleRad;
				return angleRad;
		}

		public static function XYAngle(xAccel : Number, yAccel : Number):Number{

				yAccel = -yAccel;
				var angleRad : Number;
				angleRad = Math.atan(yAccel/xAccel) * (180.0/Math.PI);
				if (xAccel >= 0.0 && yAccel <= 0.0)
					angleRad = 360.0 + angleRad;
				else if (xAccel <=0.0 && yAccel <=0.0)
					angleRad = 180.0 + angleRad;
				else if (xAccel<= 0.0 && yAccel>=0.0)
					angleRad = 180.0 + angleRad;
				return angleRad;
			}
		
	
	}
}